#!/usr/bin/env python
# Problem Set 1 
# Name: Noah Spahn 
# Collaborators: none 
# Time: 1:30 hours
# 11.8.09

import math
from math import *
def prime(num):
    """Decides whether or not a number is prime"""
    if num<9:
        for x in range (2, num):
            if num%x==0:
                return 1
    for x in range (2, int(math.sqrt(num))+1): 
        if num%x == 0:  # if remainder is 0, the number is not prime
            return 1
        
def getPrimes(upToNum):
    """ Generates a list of Prime Numbers from 2 until the 'n-th' number is reached"""
    list = []
    for val in range(2, 10000): #---Generate range of numbers
        pr = prime(val)
        if pr != 1:   # if returned value is 1, the number isn't prime
            list.append(val); #canidate is prime, add it to the list
            if len(list) == upToNum:
                print val
                break
            
def calcLogsOfPrimes(upToNum):
    """Computes the sum of the logarithms of all the primes from 2 to some
number n.
Prints out the sum of the logs of the primes, the number n, and the ratio of these
two quantities. 
Tested for different values of n.
"""      
    #list = []
    sum = 0
    for val in range(2,upToNum+1): #---Generate range of numbers
        pr = prime(val)
        if pr != 1:   # if returned value is 1, the number isn't prime
            sum+=log(val) #list.append(val) #canidate is prime, add it to the list
            #if len(list) == upToNum:
    print "Sum:", sum
    print "Number 'n':", upToNum 
    print "Ratio:", sum/upToNum     
calcLogsOfPrimes(130)
#getPrimes(100)
###  RESOURCES ###
# http://en.wikipedia.org/wiki/Logarithm